Skip to content

Add browser navigation event#2806

Closed
martinkuba wants to merge 5 commits into
open-telemetry:mainfrom
martinkuba:browser-navigation-event
Closed

Add browser navigation event#2806
martinkuba wants to merge 5 commits into
open-telemetry:mainfrom
martinkuba:browser-navigation-event

Conversation

@martinkuba
Copy link
Copy Markdown
Contributor

@martinkuba martinkuba commented Sep 25, 2025

Changes

This adds a browser event for capturing navigation actions.

Proposed here

Merge requirement checklist

  • CONTRIBUTING.md guidelines followed.
  • Change log entry added, according to the guidelines in When to add a changelog entry.
    • If your PR does not need a change log, start the PR title with [chore]
  • Links to the prototypes or existing instrumentations (when adding or changing conventions)

@github-actions github-actions Bot added enhancement New feature or request area:browser labels Sep 25, 2025

| Attribute | Type | Description | Examples | [Requirement Level](https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/) | Stability |
|---|---|---|---|---|---|
| [`browser.navigation.same_document`](/docs/registry/attributes/browser.md) | boolean | A boolean that is true if the navigation is within the same document [1] | `true`; `false` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Any reason to set this attribute as required? I'm worried about browser support here, since the Navigation API is not yet supported in Firefox and Safari.

At the same time, I'm also wondering about the relevance of this attribute: are we expecting the SDK to collect navigation entries related to past documents? Shouldn't those entries already be collected when the past document was active, in which case this attribute would always be true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indicates whether the navigation resulted in loading a new document. I felt it was important to capture because it is the main indicator to specifically distinguish hard page loads.

For Firefox and Safari, we can instrument the History API. Any call to history.pushState or history.replaceState should be captured as same_document = true, while the event captured when the page is first loading should be same_document = false.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indicates whether the navigation resulted in loading a new document.

Forgive me if I'm wrong as I am new to the Navigation API, but from my tests it doesn't seem to be the case. sameDocument indicates that the NavigationHistoryEntry was on the current document (also the doc seems to confirm this).

Test:

  • load https://example.com/
  • in the devtools, look at navigation.currentEntry.sameDocument. It should be true (even if it's a whole new document)
  • Make a soft navigation using history.pushState(null, '', 'foo') then look at navigation.entries(). A new navigation entry was added to the list, and both entries have sameDocument: true
  • Make a hard navigation using location.href = '/' then look at navigation.entries() again. A new navigation entry with sameDocument: true was added to the list, and the first two entries sameDocument became false.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh I understand your point of view as you are referring to the navigateEvent.destination.sameDocument property. In this case yes it distinguishes between soft and hard navigations, but I don't think we should collect hard navigations this way? The hard navigation should be collected after the page is loaded, no?

| [`browser.navigation.same_document`](/docs/registry/attributes/browser.md) | boolean | A boolean that is true if the navigation is within the same document [1] | `true`; `false` | `Required` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`url.full`](/docs/registry/attributes/url.md) | string | Absolute URL describing a network resource according to [RFC3986](https://www.rfc-editor.org/rfc/rfc3986) [2] | `https://www.foo.bar/search?q=OpenTelemetry#SemConv`; `//localhost` | `Required` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
| [`browser.navigation.hash_change`](/docs/registry/attributes/browser.md) | boolean | A boolean that is true if the navigation is a fragment navigation. [3] | `true`; `false` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
| [`browser.navigation.type`](/docs/registry/attributes/browser.md) | string | The type of navigation [4] | `push`; `replace`; `reload`; `traverse` | `Recommended` | ![Development](https://img.shields.io/badge/-development-blue) |
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how much of a benefit we would have in resembling the Navigation event from Browser spec which is basically a History change activity. For Spec, we would be better off capturing this as hard-navigation, soft-navigation, route-change, click etc that triggered the navigations.

I don't think we need to be in 1-1 with Browser Spec.

If we take this route, it would be easier to group all the navigations that are associated within a Session in the backend.

We can also eliminate all the other hashChange, sameDocument fields are the SDK can basically trigger a pageView event dictating whether it was a navigation event that happened due to this type.

@github-actions
Copy link
Copy Markdown

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions
Copy link
Copy Markdown

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions
Copy link
Copy Markdown

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions Bot added the Stale label Nov 13, 2025
@lmolkova lmolkova removed the Stale label Nov 20, 2025
@lmolkova lmolkova moved this from Untriaged to Awaiting codeowners approval in Semantic Conventions Triage Nov 20, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 5, 2025

This PR has been labeled as stale due to lack of activity. It will be automatically closed if there is no further activity over the next 14 days.

@martinkuba martinkuba moved this to In Progress in Browser: Phase 1 Feb 5, 2026
@martinkuba martinkuba self-assigned this Feb 5, 2026
@github-actions github-actions Bot removed the Stale label Feb 6, 2026
@github-actions
Copy link
Copy Markdown

This PR has been labeled as stale due to lack of activity. It will be automatically closed if there is no further activity over the next 7 days.

@github-actions github-actions Bot added the Stale label Feb 20, 2026
@github-actions github-actions Bot closed this Feb 28, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Browser: Phase 1 Feb 28, 2026
@martinkuba martinkuba reopened this Mar 5, 2026
@github-actions github-actions Bot removed the Stale label Mar 6, 2026
@martinkuba martinkuba mentioned this pull request Mar 18, 2026
3 tasks
@martinkuba martinkuba moved this from Done to In Progress in Browser: Phase 1 Mar 18, 2026
@github-actions
Copy link
Copy Markdown

This PR has been labeled as stale due to lack of activity. It will be automatically closed if there is no further activity over the next 7 days.

@github-actions github-actions Bot added the Stale label Mar 20, 2026
@github-actions github-actions Bot closed this Mar 27, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Browser: Phase 1 Mar 27, 2026
@martinkuba martinkuba reopened this Mar 27, 2026
@github-actions github-actions Bot removed the Stale label Mar 28, 2026
@github-actions
Copy link
Copy Markdown

This PR has been labeled as stale due to lack of activity. It will be automatically closed if there is no further activity over the next 7 days.

@github-actions github-actions Bot added the Stale label Apr 11, 2026
@github-actions github-actions Bot closed this Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done
Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants